import { defineStore } from 'pinia'
import Cookies from 'js-cookie'

const useAppStore = defineStore('app', {
  state: () => ({
    // 侧边栏是否折叠
    sidebarCollapse: Cookies.get('sidebarCollapse') === 'true' || false,
    // 当前主题
    theme: Cookies.get('theme') || 'light',
    // 语言
    language: Cookies.get('language') || 'zh-CN'
  }),
  actions: {
    // 切换侧边栏状态
    toggleSidebar() {
      this.sidebarCollapse = !this.sidebarCollapse
      Cookies.set('sidebarCollapse', this.sidebarCollapse)
    },
    // 设置主题
    setTheme(theme) {
      this.theme = theme
      Cookies.set('theme', theme)
    },
    // 设置语言
    setLanguage(lang) {
      this.language = lang
      Cookies.set('language', lang)
    }
  }
})

export default useAppStore
